import wx
import os, sys
import math

APPLICATION_INSTALL_DIR = os.environ.get('SIMPLEWATCHER_INSTALL')
if not APPLICATION_INSTALL_DIR:
    raise EnvironmentError("must set environment variable SIMPLEWATCHER_INSTALL")
sys.path.append('%s/lib' % APPLICATION_INSTALL_DIR)


def wxImageBuilder(filename):
    image_file = os.path.join(APPLICATION_INSTALL_DIR, "lib%swatch_builder%sgui%simages%s%s" % (os.sep, os.sep, os.sep, os.sep, filename))
    if not os.path.isfile(image_file):
        raise TypeError("Image file is not a readable file!  path given is %s" % image_file)
    image = wx.Bitmap(image_file, type=wx.BITMAP_TYPE_ANY)
    return image


def calculateDistance(loc1, loc2):
    loc1x, loc1y = loc1
    loc2x, loc2y = loc2
    dx = float(loc1x - loc2x)
    dy = float(loc1y - loc2y)
    return math.sqrt(dy*dy + dx*dx)